package com.hephesto.infra.security.crypto.engines;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.hephesto.infra.security.crypto.ICryptographer;
import com.hephesto.infra.security.crypto.helper.CryptographerHelper;
import com.hephesto.infra.security.crypto.model.CryptographerException;

/**
 * @author rocha
 *
 */
public class CryptographerBehaviorSHA256 implements ICryptographer  {
	
	/**
	 * 
	 */
	private static final String MESSAGE_EXCEPTION_CANNOT_DECRYPT = 
		"i can't decrypt. i'm cryptographer assimetric.";
	
	/**
	 * @see com.hephesto.infra.security.crypto.ICryptographerSimetric#encrypt(byte[])
	 */
	@Override
	public byte[] encrypt(byte[] bytes) throws CryptographerException {
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-256");
			md.update(bytes);
			byte[] digest = md.digest();

			return CryptographerHelper.byteArrayToHexString(digest).getBytes();
		} catch (NoSuchAlgorithmException e) {
			throw new CryptographerException(e.getMessage(), e);
		}
	}

	/**
	 * @see com.thm.infra.security.crypto.ICryptographer#decrypt(byte[])
	 */
	@Override
	public byte[] decrypt(byte[] bytes) throws CryptographerException {
		if (true)
			throw new CryptographerException( MESSAGE_EXCEPTION_CANNOT_DECRYPT );
		return null;
	}
	
}